package com.hln.jingwushi.ui.dialog

import android.content.Context
import android.os.Bundle
import com.hln.jingwushi.bean.VideoMonitoringBean
import com.hln.jingwushi.databinding.DialogVmUpdateBinding
import com.hln.jingwushi.utils.VideoInfoCacheUtil
import com.gdsz.libbasic.view.ui.BaseDialog

class VMUpdateDialog(context: Context,theme: Int,var mVideoMonitoringBean: VideoMonitoringBean,val cb: CB) : BaseDialog<DialogVmUpdateBinding>(context,theme) {
    override fun DialogVmUpdateBinding.initBinding(savedInstanceState: Bundle?) {
        setCanceledOnTouchOutside(false)
        binding.etName.setText(mVideoMonitoringBean.name)
        binding.etUrl.setText(mVideoMonitoringBean.url)
        binding.btnCancel.setOnClickListener {
            dismiss()
        }
        binding.btnSure.setOnClickListener {
            mVideoMonitoringBean.url = binding.etUrl.text.toString().trim()
            mVideoMonitoringBean.name = binding.etName.text.toString()
            when (mVideoMonitoringBean.index.toInt()) {
                1 -> {
                    VideoInfoCacheUtil.setUrl1(mVideoMonitoringBean)
                }
                2 -> {
                    VideoInfoCacheUtil.setUrl2(mVideoMonitoringBean)
                }
                3 -> {
                    VideoInfoCacheUtil.setUrl3(mVideoMonitoringBean)
                }
                4 -> {
                    VideoInfoCacheUtil.setUrl4(mVideoMonitoringBean)
                }
                5 -> {
                    VideoInfoCacheUtil.setUrl5(mVideoMonitoringBean)
                }
                6 -> {
                    VideoInfoCacheUtil.setUrl6(mVideoMonitoringBean)
                }
                7 -> {
                    VideoInfoCacheUtil.setUrl7(mVideoMonitoringBean)
                }
                8 -> {
                    VideoInfoCacheUtil.setUrl8(mVideoMonitoringBean)
                }
            }
            cb.sure()
            dismiss()
        }
    }

    interface CB {
        fun sure()
    }
}